package com.cangshi.permission.session.entity;

import java.io.Serializable;
import java.util.HashMap;

/**
 * Created by Eoly on 2017/4/17.
 */
public class Session<K,V> extends HashMap<K,V> {

    private Serializable identificationKey;
    private Boolean isOnline = true;
    private String sessionId;
    private SessionCacheManager sessionCacheManager;


    public Session(String sessionId, SessionCacheManager sessionCacheManager) {
        this.sessionId = sessionId;
        this.sessionCacheManager = sessionCacheManager;
    }

    public Serializable getIdentificationKey() {
        return identificationKey;
    }

    public void setIdentificationKey(Serializable identificationKey) {
        this.identificationKey = identificationKey;
        this.sessionCacheManager.updateSession(sessionId, (Session<String, Object>) this);
    }

    public Boolean getOnline() {
        return isOnline;
    }

    public void setOnline(Boolean online) {
        isOnline = online;
        this.sessionCacheManager.updateSession(sessionId, (Session<String, Object>) this);
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public SessionCacheManager getSessionCacheManager() {
        return sessionCacheManager;
    }

    public void setSessionCacheManager(SessionCacheManager sessionCacheManager) {
        this.sessionCacheManager = sessionCacheManager;
    }

    public void addAttribute(K key,V value){
        sessionCacheManager.addSessionAttribute(sessionId, (String) key,value);
    }

    public V getAttribute(K key){
        return this.get(key);
    }
}
